package day4;
//测试Object类
public class TestObject{
    String name;
    int age;
    public static void main(String[] args) {
//        TestObject t=new TestObject();
//        System.out.println(t);
//        String s="java";
//        String s2=new String("java");
//        System.out.println(s);
//        System.out.println(s2);
//        StringBuilder sb=new StringBuilder("java");
//        System.out.println(s.equals(s2)); //true
//        System.out.println(s.equals(sb));//false
//        System.out.println(sb.equals("java"));//false
//        System.out.println(s==s2); //false
//        TestObject t2=new TestObject();
//        System.out.println(t.equals(t2));


        //第一类:对象类
        TestObject t1=new TestObject();
        TestObject t2=t1;
        TestObject t3=new TestObject();
        System.out.println("t1:"+t1.hashCode());
        System.out.println("t2:"+t2.hashCode());
        System.out.println("t3:"+t3.hashCode());
        //第二类:基本类型封装类 Integer Long Byte Float ...
        Integer num=1000;
        Integer num2=new Integer(1000);
        Long num3=1000l;
        System.out.println("num:"+num.hashCode());
        System.out.println("num2:"+num2.hashCode());
        System.out.println("num3:"+num3.hashCode());
        //第三类:String类, 可能会出现个bug,
        //哈希冲突: 值是不同的 但是hashcode反而相同
        String s1="java";
        String s2=new String("java");
        System.out.println("s1:"+s1.hashCode());
        System.out.println("s2:"+s2.hashCode());
        //存在哈希冲突
        String s3="重地";
        String s4="通话";
        System.out.println("s3:"+s3.hashCode());
        System.out.println("s4:"+s4.hashCode());
    }

    public boolean equals(Object obj) {
        return true;
    }
    public String toString() {
        return "name:"+name+",age:"+age;
    }
}
